//
//  PrepaidFeeVC.m
//  test
//
//  Created by 李彦宏 on 2018/3/8.
//  Copyright © 2018年 朱圳. All rights reserved.
//已付费课酬

#import "PrepaidFeeVC.h"
#import "JWGRkcHaveMoneyCell.h"//课酬cell
#import "JWGRkcHaveMoneyHead.h"//头
#import "JWGRLookPicture.h"//查看截图
#import "JWKCFeemodel.h"//课酬model
#import "JWUserManager.h"
#import "JWGRUsermodel.h"

@interface PrepaidFeeVC ()<UITableViewDelegate,UITableViewDataSource>
@property (nonatomic, strong) NSMutableArray *contArry;
@property (nonatomic, strong) UITableView *tableView;
@property (nonatomic, strong) JWKCFeemodel *model;
@property (nonatomic, strong) JWGRUsermodel *Gmodel;

@end

@implementation PrepaidFeeVC

//UItableView初始化
- (void)setupTable
{
    UITableView *tableView=[[UITableView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, ScreenHeight) style:UITableViewStylePlain];

    tableView.backgroundColor=[UIColor whiteColor];
    tableView.showsHorizontalScrollIndicator=NO;
    tableView.showsVerticalScrollIndicator=NO;
    tableView.dataSource=self;
    tableView.delegate=self;
    //自适应cell
    tableView.estimatedRowHeight = 120;
    tableView.rowHeight = UITableViewAutomaticDimension; tableView.separatorStyle=UITableViewCellSeparatorStyleNone;
    [self.view addSubview:tableView];
    self.tableView=tableView;
    
    
}

-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    
     [self setdata];
    
}
- (void)viewDidLoad {
    [super viewDidLoad];
    [self setupTable];
    self.Gmodel=[JWUserManager Gme];
    self.view.backgroundColor = [UIColor whiteColor];
}

#pragma -mark -----------------------------tableview datasource and delegate---------------------------------
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return _contArry.count;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 45;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    JWGRkcHaveMoneyCell *cell=[JWGRkcHaveMoneyCell cellwithTableview:tableView];
   

    cell.model=self.contArry[indexPath.row];
[cell setAddImageBlock:^{
    self.model=self.contArry[indexPath.row];
    
    JWGRLookPicture *vc=[[JWGRLookPicture alloc]init];
    vc.title=[NSString stringWithFormat:@"%@的打款详情",self.Gmodel.name];
    vc.arry=[[NSMutableArray alloc]init];
    
    [vc.arry addObject:self.model];
    
    [self.navigationController pushViewController:vc animated:YES];
    
    }];
cell.selectionStyle=UITableViewCellSelectionStyleNone;
    return cell;
   
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [self.tableView deselectRowAtIndexPath:indexPath animated:YES];
    
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 40;
}


- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    return 1;
}

#pragma -mark 头部的内容
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
        JWGRkcHaveMoneyHead *header=[[JWGRkcHaveMoneyHead alloc]init];
        
        return header;
  
}
#pragma -mark —————————————已打款课酬数据————————————————————
-(void)setdata{
    [EasyShowLodingView showLodingText:@""];
    if(self.Gmodel.ID==nil){
        self.Gmodel.ID=self.Gmodel.gid;
    }
    NSDictionary *dic=@{
                        @"jwid" : JWid,
                        @"jwpassword" : JWpassword,
                        @"gid":self.Gmodel.ID,
                        };
    NSLog(@"--dic--%@", dic);
    [[AFNetworkTool shareManager]postJSONWithUrl:JW_KCRepay parmas:dic successData:^(id json) {
        [self.contArry removeAllObjects];
        NSArray *arry=json[@"list"];
        for(int i=0;i<arry.count;i++){
            self.model=[JWKCFeemodel yy_modelWithJSON:arry[i]];
            
            [self.contArry addObject:self.model];
            
        }
        
        __weak typeof(self) weakslf = self;
        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.3 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
            NSInteger cout=self.contArry.count;
            if(cout==0){
                [self.tableView removeFromSuperview];
                KongDataView *konview=[KongDataView NilDataview];
                konview.frame=self.view.frame;
                [self.view addSubview:konview];
            }
            [EasyShowLodingView hidenLoding];
            [weakslf.tableView reloadData];
            
        });
        
    } failure:^(NSError *error) {
        NSLog(@"--error--%@", error);
    }];
}
-(NSMutableArray *)contArry{
    if(_contArry==nil){
        _contArry=[[NSMutableArray alloc]init];
    }
    return _contArry;
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
